package com.dimples.dd.auth.controller;

import com.dimples.dd.auth.core.captcha.service.ValidateCodeService;
import com.dimples.dd.web.exception.ValidateCodeException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.Principal;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/5/23
 */
@Tag(name = "Auth")
@RestController
@RequestMapping("auth")
@RequiredArgsConstructor
public class SecurityController {

    private final ValidateCodeService validateCodeService;

    @Operation(summary = "获取验证码")
    @GetMapping("/captcha")
    public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws ValidateCodeException, IOException {
        validateCodeService.create(request, response);
    }

    @Operation(summary = "测试oauth2")
    @GetMapping("oauth/test")
    public String testOauth() {
        return "oauth";
    }

    @Operation(summary = "获取当前user")
    @GetMapping("user")
    public Principal currentUser(Principal principal) {
        return principal;
    }

}
